package com.heima.feigns;

import com.heima.config.HeimaFeignAutoConfiguration;
import com.heima.feigns.fallback.ArticleFeignFallback;
import com.heima.model.article.dtos.StatisticsDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "leadnews-article",
        fallbackFactory = ArticleFeignFallback.class,
        configuration = HeimaFeignAutoConfiguration.class
)
public interface ArticleFeign {
    @GetMapping("/api/v1/author/findByUserId/{userId}")
    ResponseResult<ApAuthor> findByUserId(@PathVariable("userId") Integer userId);

    @PostMapping("/api/v1/author/save")
    ResponseResult save(@RequestBody ApAuthor apAuthor);

    @GetMapping("/api/v1/article/{id}")
    public ResponseResult<ApArticle> findArticle(@PathVariable(value = "id") Long id);

    /**
     * 根据前日期后日期查询对应文章集合
     *
     * @param preTime 前时间
     * @param beTime  后时间
     * @return
     */
    @PostMapping("/api/v1/article/all")
    public ResponseResult<List<ApArticle>> findAllArticle(
            @RequestParam(value = "preTime") String preTime,
            @RequestParam(value = "beTime") String beTime);

    //根据作者查询文章
    @GetMapping("/api/v1/article/list/{id}")
    ResponseResult<List<ApArticle>> findArticleByAuthorId(@PathVariable("id") String id);

    //查询作者
    //上面查询作者的方法有问题,应该该为wm_user_id,我自己重新写了个,没有改变原来的代码
    @GetMapping("/api/v1/author/findById/{userId}")
    public ResponseResult<ApAuthor> findAuthorByUserId(@PathVariable("userId") Integer userId);


    //查询作者的文章的阅读量,评论量,数据统计的时候使用
    @RequestMapping("/api/v1/article/statistics/news")
    Map statisticsNews(@RequestBody StatisticsDto dto);

    @RequestMapping("/api/v1/article/statistics/news/date")
    public List<ApArticle> findApArticleByDateAndAuthorId(@RequestParam("date")String date,
                                                          @RequestParam("authorId")String authorId);

}